package de.placidi.pressreview.parsing;


/**
 * Represents an url. Has a depth, which is the number of calls from given main site. 
 * 
 * @author Alexander Placidi
 *
 */
public final class Link implements Comparable<Link>{
	
	private String url;
	private int depth;
	
	public Link(String url, int depth) {
		super();
		this.url = url;
		this.depth = depth;
	}

	public String getUrl() {
		return url;
	}

	public int getDepth() {
		return depth;
	}
	
	@Override
	public int compareTo(Link l) {
		int c = 0;
		
		if (l.getDepth() < this.getDepth()) {
			c = -1;
		}
		
		if (l.getDepth() > this.getDepth()) {
			c = 1;
		}
		
		return c;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((url == null) ? 0 : url.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Link other = (Link) obj;
		if (url == null) {
			if (other.url != null)
				return false;
		} else if (!url.equals(other.url))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Link [url=" + url + ", depth=" + depth + "]";
	}
	
	
}
